home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16156 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  30 lines

  1. Newsgroups: comp.lang.c++
  2. Path: in2.uu.net!allegra!alice!ark
  3. From: ark@research.att.com (Andrew Koenig)
  4. Subject: Re: Arrays or Pointers?
  5. Message-ID: <DpLq0z.3A8@research.att.com>
  6. Organization: AT&T Research, Murray Hill NJ
  7. References: <4kbsk3$f07@zeus.tcp.co.uk> <4kdatp$kcp@grimsel.zurich.ibm.com>
  8. Date: Tue, 9 Apr 1996 15:36:34 GMT
  9.  
  10. So far, no one has mentioned what I think is the most important
  11. difference between arrays+subscripts and pointers: A pointer
  12. identifies a particular element in a particular array while using
  13. only a single value.  With subscripts, it takes two values: the
  14. array and the index of the array.
  15.  
  16. Suppose, for example, that you want to write a function that
  17. reverses the elements of some part of an array.  If you do not
  18. use pointers, your function needs three arguments: the array,
  19. the index of the first element, and the index of the last element.
  20. If you use pointers, the function needs only two arguments.
  21.  
  22. On the other hand, once you have a pointer to an array element,
  23. there is no easy way to recover the identity of the array.
  24.  
  25. Considerations like these are almost always more important
  26. than sheer speed, which is likely to be compiler-dependent anyway.
  27. -- 
  28.                 --Andrew Koenig
  29.                   ark@research.att.com
  30.